<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/10/22
 * Time: 16:05
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\common\model\mysql;

use app\common\lib\Status;

class Banner extends Base
{
    public function getImgUrlAttr($value)
    {
        return (string)url("/" . $value, [], false, true);
    }

    public function getGetExtAttr($src)
    {
        $ext = explode(".", $src);
        $ext_string = "image";
        if (in_array($ext[1], config('type_ext.image'))) {
            $ext_string = "image";
        } else if (in_array($ext[1], config('type_ext.video'))) {
            $ext_string = "video";
        }
        return $ext_string;
    }
    public function getTypeAttr($value){
        $config = config('banner_type');
        return $config[$value];
    }
    public function getBannerByTypeList(int $type = 1){
        return $this->field('*,img as get_img,thumb as get_thumb,img as get_ext')
            ->where('type',$type)
            ->where('status',Status::mysql_normal)
            ->order('sort desc,id desc')
            ->select()
            ->toArray();
    }
    protected function getGetImgAttr($value){
        return (string)url("/".$value,[],false,true);
    }
    protected function getGetThumbAttr($value){
        return (string)url("/".$value,[],false,true);
    }
}